package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"regexp"
)

const (
	// 正则表达式，匹配出 XL 的账号密码
	reAccount = `(账号|迅雷账号)(；|：)[0-9:]+(| )密码：[0-9a-zA-Z]+`
)

func getInfo(url string) {
	resp, err := http.Get(url)
	if err != nil {
		log.Fatal("http.Get error: ", err)
	}
	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {
			log.Fatal("response err: ", err)
		}
	}(resp.Body)

	dataByte, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal("data read error", err)
	}

	data := string(dataByte)

	// 过滤
	re := regexp.MustCompile(reAccount)

	results := re.FindAllStringSubmatch(data, -1)
	for _, result := range results {
		fmt.Println(result[0])
	}
	//return results[0][0]
}

//func main() {
//	c := colly.NewCollector()
//
//	// Find and visit all links
//	//c.OnHTML("a[href]", func(e *colly.HTMLElement) {
//	//	//e.Request.Visit(e.Attr("href"))
//	//
//	//})
//
//	c.OnRequest(func(r *colly.Request) {
//		fmt.Println("Visiting", r.URL)
//	})
//	c.OnResponse(func(response *colly.Response) {
//		fmt.Println(response.Body)
//	})
//
//	err := c.Visit("https://api.zsxq.com/v2/hashtags/28851422588481/topics?count=20")
//	if err != nil {
//		return
//	}
//}

//func main() {
//	//fmt.Println("sdada")
//	getInfo("http://www.ucbug.com/jiaocheng/63149.html?_t=1582307696")
//}

//:authority: api.zsxq.com
//:method: GET
//:path: /v2/hashtags/28851422588481/topics?count=20
//:scheme: https
//accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
//accept-encoding: gzip, deflate, br
//accept-language: zh-CN,zh;q=0.9
//cache-control: max-age=0
//user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
